#!/usr/bin/python
# Something to export the markers etc to a CSV file so they can be tinkered with en mass
# and/or reimported when the database schema changes.

from pottononline.map.models import Icon, MarkerType, Marker
import csv


fields = Marker.objects.values()[0].keys()
mylist = []
mydict = {}

# create a header row
for field in fields:
  mydict[field] = field
mylist.append(mydict)

# followed by the data
for each in Marker.objects.all():
  mydict={}
  for field in fields:
    value = each.__getattribute__(field)
    mydict[field] = value
  mylist.append(mydict)

file = open("mydata.csv", "wb")
csvfile = csv.DictWriter(file, fields)
csvfile.writerows(mylist)

file.close()

